#include <iostream>
#include <memory>
#include <vector>
using std::cout;
using std::endl;
using std::unique_ptr;
using std::vector;

class Point
{
public:
    Point(int ix = 0, int iy = 0)
    : _ix(ix)
    , _iy(iy)
    {
        cout << "Point(int,int)" << endl;
    }

    void print() const{
        cout << "(" << _ix
            << "," <<_iy
            << ")" << endl;
    }

    ~Point(){
        cout << "~Point()" << endl;
    }

private:
    int _ix;
    int _iy;
};

void test0(){
    unique_ptr<int> up(new int(10));
    cout << "*up:" << *up << endl;
    cout << "up.get():" << up.get() << endl;

    unique_ptr<int> up3(new int(10));

    /* unique_ptr<int> up2 = up; */
    /* up3 = up; */
}

void test1(){
    unique_ptr<Point> up(new Point(10,20));
    vector<unique_ptr<Point>> vec;
    //这里调用了unique_ptr的拷贝构造
    //需要让unique_ptr以右值的属性交给vector的push_back
    /* vec.push_back(up); */

    vec.push_back(unique_ptr<Point>(new Point(2,8)));
    vec[0]->print();

    //利用unique_ptr的移动构造创建出新的unique_ptr作为vector的元素
    //up对堆上的Point对象的管理权被移交给这个新的unique_ptr
    vec.push_back(std::move(up));
    vec[1]->print();

    /* up->print(); */
}

int main(void){
    test1();
    return 0;
}

